/*
 * @Author: zwf 240970521@qq.com
 * @Date: 2023-07-24 22:30:44
 * @LastEditors: zwf 240970521@qq.com
 * @LastEditTime: 2023-08-18 20:41:02
 * @FilePath: /esp32_motor/motor/inc/pid.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef PID_H
#define PID_H

#include "esp_err.h"
#include "IQmathLib.h"

typedef struct PidConfig
{
    _iq24 p;
    _iq24 i;
    _iq24 d;
    _iq24 limit;
    _iq20 outputRamp;
    _iq24 ts;
} PidConfig;

typedef struct PidControl
{
    void *priv;
    _iq24 (*getRefValue)(struct PidControl *control, _iq24 errorValue);
    void (*setPID)(struct PidControl *control, _iq24 p, _iq24 i, _iq24 d);
} PidControl;

esp_err_t PID_create(PidControl **control, PidConfig cfg);
void      PID_delete(PidControl *control);

#endif
